import java.util.PriorityQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
//import java.util.concurrent.ArrayBlockingQueue;
//import java.util.concurrent.BlockingDeque;
//import java.util.concurrent.LinkedBlockingDeque;

public class Demo3 {
    public static void main(String[] args) {
        BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<>(100);

        Thread producer = new Thread(() -> {
            int num = 0;
           while (true) {
               try {
                   blockingDeque.put(num);
                   System.out.println("生产" + num++);
//                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });

        Thread consumer = new Thread(() -> {
            while (true) {
                try {
                    int num = blockingDeque.take();
                    System.out.println("消费" + num);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        producer.start();
        consumer.start();
    }
}
